package net.hzlj.platform.enterprise.socket;

import net.hzlj.platform.enterprise.BootApp;
import net.hzlj.platform.enterprise.common.Constant;
import net.hzlj.platform.enterprise.socket.impl.MinaSocketImpl;
import net.hzlj.platform.enterprise.socket.impl.NettySocketImpl;
import net.hzlj.platform.enterprise.socket.netty.NettyClientManager;

/**
 * @Description:
 * @Author: Jason Zhang
 * @Date: 2017/06/28
 */

public class SocketManager implements SocketService {

    public static final String TAG = SocketManager.class.getSimpleName();

    private static final SocketManager instance = new SocketManager();

    private SocketService socketService;


    public static SocketManager getInstance(){
        return instance;
    }

    private SocketManager(){
        if (Constant.Socket.CONNECTION_TYPE == Constant.Socket.TYPE.NETTY){
            socketService = new NettySocketImpl();
        }else {
            socketService = new MinaSocketImpl();
        }
    }

    @Override
    public void reconnect() {
        socketService.reconnect();
        //BootApp.getInstance().sendBroadcast(Constant.Intent.ACTION_SCOKET_RECONNECT,null);
    }

    @Override
    public void sendMessage(String message) {
        socketService.sendMessage(message);
        //BootApp.getInstance().sendBroadcast(Constant.Intent.ACTION_SCOKET_MESSAGE_SEND,message);
    }

    @Override
    public void close() {
        socketService.close();
        //BootApp.getInstance().sendBroadcast(Constant.Intent.ACTION_SCOKET_CLOSE,null);
    }

    @Override
    public boolean isConnection() {
        return socketService.isConnection();
    }
}
